<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <title>JSNES Benchmark</title>
    
    <script src="../lib/jquery-1.4.2.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../source/nes.js" type="text/javascript" charset="utf-8"></script>
    <script src="../source/utils.js" type="text/javascript" charset="utf-8"></script>
    <script src="../source/cpu.js" type="text/javascript" charset="utf-8"></script>
    <script src="../source/keyboard.js" type="text/javascript" charset="utf-8"></script>
    <script src="../source/mappers.js" type="text/javascript" charset="utf-8"></script>
    <script src="../source/papu.js" type="text/javascript" charset="utf-8"></script>
    <script src="../source/ppu.js" type="text/javascript" charset="utf-8"></script>
    <script src="../source/rom.js" type="text/javascript" charset="utf-8"></script>
    <script src="../source/ui.js" type="text/javascript" charset="utf-8"></script>
    
    <script src="base64.js" type="text/javascript" charset="utf-8"></script>
    <script src="benchmark.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" charset="utf-8">
        $(function() {
            var currentRepeat = -1;
            var repeatCount = 1;
            var frameCount = 100;
            var results = [];
            var i;
            results.length = repeatCount;
            $('#results').append('<li>Running...</li>');
            setTimeout(function benchmark() {
                if (currentRepeat < repeatCount) {
                    var start = +new Date();
                    
                    croomBenchmark();
                    
                    // Warm up runs
                    if (currentRepeat >= 0) {
                        results[currentRepeat] = +new Date() - start;
                        $('#results').append('<li>Run '+currentRepeat+', '+results[currentRepeat]+'ms</li>');
                    }
                    currentRepeat += 1;
                    setTimeout(benchmark, 10);
                }
                else {
                    var totalTime = 0;
                    for (i=0; i<results.length; i++) {
                        totalTime += results[i];
                    }
                    var meanTime = totalTime / repeatCount;
                    var totalFPS = 0;
                    for (i=0; i<results.length; i++) {
                        totalFPS = frameCount / (results[i] / 1000);
                    }
                    var meanFPS = totalFPS / repeatCount;
                    $('#results').append('<li>Average of 10 runs: '+meanTime.toFixed(2)+'ms</li>');
                }
            }, 10);
        });
    </script>
</head>
<body>
    <h1>JSNES Benchmark</h1>
    <ul id="results"></ul>
</body>
</html>
